package com.pms.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.pms.entity.Document;
import com.pms.service.NewDocumentService;

public class EditDocument extends HttpServlet {


	private static final long serialVersionUID = 1L;

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		
		String doid=request.getParameter("doid");
		System.out.println(doid+"dociddddddddddddd");
		
		NewDocumentService newds=new NewDocumentService();
		Document doc=newds.findById(doid);
		System.out.println(doc);
		request.setAttribute("doc", doc);
		
		request.getRequestDispatcher("/WEB-INF/editDocument.jsp").forward(request, response);
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		req.setCharacterEncoding("utf-8");
		String doid=req.getParameter("doid");
		String title=req.getParameter("title");
		String content=req.getParameter("content");
		System.out.println(doid+title+content);
		
		new NewDocumentService().editDoc(doid,title,content);
		resp.sendRedirect("document.jspx");
		
	}
}
